package org.jeecg.common;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.jeecg.test.TestServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @author xiaoxiyuan
 * @description 编码器
 * @date 2020-06-11 15:28:41
 */
public class MessageEncoder extends MessageToByteEncoder<MessageProtocol> {
    TestServiceImpl service;
    private ApplicationContext applicationContext;

    public MessageEncoder(ApplicationContext applicationContext){
        this.applicationContext=applicationContext;
    }
    public MessageEncoder(){
        this.applicationContext=applicationContext;
    }


    @Override
    public void encode(ChannelHandlerContext ctx, MessageProtocol messageProtocol, ByteBuf out) throws Exception {
        System.out.println("MessageEncoder encode 方法被调用");
        out.writeInt(messageProtocol.getLen());
        out.writeBytes(messageProtocol.getContent());
    }
}

